package cn.udrm.water.base.v1.manager.repository;

import org.springframework.data.jpa.repository.EntityGraph;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.jpa.repository.EntityGraph.EntityGraphType;
import org.springframework.stereotype.Repository;

import cn.udrm.water.base.v1.manager.entities.BasePerson;

@Repository
public interface BasePersonRepository extends JpaRepository<BasePerson, String> {

	@Query(value="FROM BasePerson WHERE id=?1")
	@EntityGraph(value="BasePerson.department", type=EntityGraphType.FETCH)
	public BasePerson findWithDepartmentById(String id);
	
	@EntityGraph(value="BasePerson.roles", type=EntityGraphType.FETCH)
	@Query(value="FROM BasePerson WHERE id=?1")
	public BasePerson findWithRolesById(String id);
	
	@Query(value="FROM BasePerson WHERE id=?1")
	public BasePerson getSelfById(String id);
}
